import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { TreeTableNode } from '@iux/live';
import { TreetableService } from '../tree-table.service';

@Component({
  selector: 'app-async-data',
  templateUrl: './async-data.component.html',
  styles: [
    `
      lv-paginator {
        margin-top: 16px;
      }
    `,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AsyncDataComponent implements OnInit {
  data: TreeTableNode[];
  constructor(private treeTableService: TreetableService, private cdr: ChangeDetectorRef) {}

  ngOnInit() {
    this.initAsyncData();
  }

  initAsyncData() {
    this.treeTableService.getUsers().subscribe((res: TreeTableNode[]) => {
      this.data = res;
      this.cdr.markForCheck();
    });
  }
}
